<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/star8kr/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/star8kr/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/star8kr/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/star8kr/images/logo.svg" color="#222">

<link rel="stylesheet" href="/star8kr/css/main.css">


<link rel="stylesheet" href="/star8kr/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/star8kr/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="注：本文首发于连享会  1. 空间权重矩阵简介空间计量经济学区别于传统计量经济学的一个最大特点便是引入了——空间权重矩阵。常用空间权重矩阵包括：邻接矩阵、距离矩阵和嵌套矩阵。在进行空间相关性分析、模型检验以及回归时，选取不同的空间权重矩阵注意往会带来不同的结果。因此，我们有必要去识别不同的空间权重矩阵，掌握其生成原理，以便更好地进行经济学研究。 1.1 邻接矩阵1.1.1 地理邻接矩阵">
<meta property="og:type" content="article">
<meta property="og:title" content="Stata 如何生成天马行空的空间权重矩阵？">
<meta property="og:url" content="https://gitee.com/star8kr/star8kr/2023/04/18/Stata%E5%A6%82%E4%BD%95%E7%94%9F%E6%88%90%E5%A4%A9%E9%A9%AC%E8%A1%8C%E7%A9%BA%E7%9A%84%E7%A9%BA%E9%97%B4%E6%9D%83%E9%87%8D%E7%9F%A9%E9%98%B5%EF%BC%9F/index.html">
<meta property="og:site_name" content="Zhang&#39;s blog">
<meta property="og:description" content="注：本文首发于连享会  1. 空间权重矩阵简介空间计量经济学区别于传统计量经济学的一个最大特点便是引入了——空间权重矩阵。常用空间权重矩阵包括：邻接矩阵、距离矩阵和嵌套矩阵。在进行空间相关性分析、模型检验以及回归时，选取不同的空间权重矩阵注意往会带来不同的结果。因此，我们有必要去识别不同的空间权重矩阵，掌握其生成原理，以便更好地进行经济学研究。 1.1 邻接矩阵1.1.1 地理邻接矩阵">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-04-18T02:36:26.542Z">
<meta property="article:modified_time" content="2023-04-18T02:40:09.177Z">
<meta property="article:author" content="zhang jiaxing">
<meta property="article:tag" content="Stata">
<meta property="article:tag" content="空间计量">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://gitee.com/star8kr/star8kr/2023/04/18/Stata%E5%A6%82%E4%BD%95%E7%94%9F%E6%88%90%E5%A4%A9%E9%A9%AC%E8%A1%8C%E7%A9%BA%E7%9A%84%E7%A9%BA%E9%97%B4%E6%9D%83%E9%87%8D%E7%9F%A9%E9%98%B5%EF%BC%9F/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Stata 如何生成天马行空的空间权重矩阵？ | Zhang's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/star8kr/atom.xml" title="Zhang's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/star8kr/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Zhang's blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">横看成岭侧成峰</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/star8kr/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/star8kr/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/star8kr/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/star8kr/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/star8kr/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/star8kr/star8kr/2023/04/18/Stata%E5%A6%82%E4%BD%95%E7%94%9F%E6%88%90%E5%A4%A9%E9%A9%AC%E8%A1%8C%E7%A9%BA%E7%9A%84%E7%A9%BA%E9%97%B4%E6%9D%83%E9%87%8D%E7%9F%A9%E9%98%B5%EF%BC%9F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/star8kr/images/avatar.gif">
      <meta itemprop="name" content="zhang jiaxing">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Zhang's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Stata 如何生成天马行空的空间权重矩阵？
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2023-04-18 10:36:26 / 修改时间：10:40:09" itemprop="dateCreated datePublished" datetime="2023-04-18T10:36:26+08:00">2023-04-18</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/star8kr/categories/Stata/" itemprop="url" rel="index"><span itemprop="name">Stata</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>18k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>44 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <blockquote>
<p> 注：本文首发于连享会</p>
</blockquote>
<h2 id="1-空间权重矩阵简介"><a href="#1-空间权重矩阵简介" class="headerlink" title="1. 空间权重矩阵简介"></a>1. 空间权重矩阵简介</h2><p>空间计量经济学区别于传统计量经济学的一个最大特点便是引入了——<strong>空间权重矩阵</strong>。常用空间权重矩阵包括：<strong>邻接矩阵、距离矩阵和嵌套矩阵</strong>。在进行空间相关性分析、模型检验以及回归时，选取不同的空间权重矩阵注意往会带来不同的结果。因此，我们有必要去识别不同的空间权重矩阵，掌握其生成原理，以便更好地进行经济学研究。</p>
<h3 id="1-1-邻接矩阵"><a href="#1-1-邻接矩阵" class="headerlink" title="1.1 邻接矩阵"></a>1.1 邻接矩阵</h3><h4 id="1-1-1-地理邻接矩阵"><a href="#1-1-1-地理邻接矩阵" class="headerlink" title="1.1.1 地理邻接矩阵"></a>1.1.1 地理邻接矩阵</h4><p>$$W_{ij}^{01}&#x3D;\begin{cases}0&amp; i与j不相邻\1 &amp;i与j相邻 \end{cases}$$</p>
<p>如果地区 i 与 地区 j 相邻，则 $W_{ij}&#x3D;1$；如果地区 i 与 地区 j 不相邻，则 $W_{ij}&#x3D;0$。</p>
<h4 id="1-1-2-广义”相邻”矩阵"><a href="#1-1-2-广义”相邻”矩阵" class="headerlink" title="1.1.2 广义”相邻”矩阵"></a>1.1.2 广义”相邻”矩阵</h4><p>$$W_{ij}^s&#x3D;\begin{cases}0&amp; i与j 不属于同一区域\1 &amp;i与j 属于同一区域 \end{cases}$$</p>
<p>如果地区 i 与 地区 j 属于同一区域，则 $W_{ij}&#x3D;1$；如果地区 i 与 地区 j 不属于同一区域，则 $W_{ij}&#x3D;0$。</p>
<h3 id="1-2-距离矩阵"><a href="#1-2-距离矩阵" class="headerlink" title="1.2 距离矩阵"></a>1.2 距离矩阵</h3><h4 id="1-2-1-地理距离矩阵"><a href="#1-2-1-地理距离矩阵" class="headerlink" title="1.2.1 地理距离矩阵"></a>1.2.1 地理距离矩阵</h4><p>(1)反距离矩阵公式</p>
<p>$$W_{ij}^d&#x3D;\begin{cases}{\frac{1}{d_{ij}}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>其中， $d_{ij}$ 为地区 i 和地区 j 之间的距离。</p>
<p>(2)反距离平方矩阵公式</p>
<p>$$W_{ij}^d&#x3D;\begin{cases}{\frac{1}{d_{ij}^2}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>其中， $d_{ij}$ 为地区 i 和地区 j 之间的距离。</p>
<h4 id="1-2-2-经济距离矩阵"><a href="#1-2-2-经济距离矩阵" class="headerlink" title="1.2.2 经济距离矩阵"></a>1.2.2 经济距离矩阵</h4><p>$$W_{ij}^e&#x3D;\begin{cases}{\frac{1}{|PGDP_i-PGDP_j|}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>其中，$PGDP_{i}$ 为地区 i 的人均 GDP ，$PGDP_{j}$ 为地区 j 的人均 GDP。 </p>
<h3 id="1-3-嵌套矩阵"><a href="#1-3-嵌套矩阵" class="headerlink" title="1.3 嵌套矩阵"></a>1.3 嵌套矩阵</h3><h4 id="1-3-1-地理经济嵌套矩阵（相加）"><a href="#1-3-1-地理经济嵌套矩阵（相加）" class="headerlink" title="1.3.1 地理经济嵌套矩阵（相加）"></a>1.3.1 地理经济嵌套矩阵（相加）</h4><p>$$W_{ij}^{de}&#x3D;\begin{cases}{\alpha \times W_{ij}^{d}+(1-\alpha) \times W_{ij}^{e}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>其中 ，$\alpha$ 为参数，$W_{ij}^{d}$ 为反地理距离矩阵，$W_{ij}^{e}$ 为经济距离矩阵。</p>
<h4 id="1-3-2-地理经济嵌套矩阵（相乘）"><a href="#1-3-2-地理经济嵌套矩阵（相乘）" class="headerlink" title="1.3.2 地理经济嵌套矩阵（相乘）"></a>1.3.2 地理经济嵌套矩阵（相乘）</h4><p>$$W_{ij}^{de}&#x3D;\begin{cases}{W_{ij}^{d} \times W_{ij}^{e}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>其中 ，$W_{ij}^{d}$ 为反地理距离矩阵，$W_{ij}^{e}$ 为经济距离矩阵。</p>
<h4 id="1-3-3-基于引力模型的矩阵"><a href="#1-3-3-基于引力模型的矩阵" class="headerlink" title="1.3.3 基于引力模型的矩阵"></a>1.3.3 基于引力模型的矩阵</h4><p>$$W_{ij}^{de}&#x3D;\begin{cases}{\frac{PGDP_i \times PGDP_j}{d_{ij}^2}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>其中，$PGDP_{i}$ 为地区 i 的人均 GDP ，$PGDP_{j}$ 为地区 j 的人均 GDP , $d_{ij}$ 为地区 i 和地区 j 之间的距离。</p>
<h2 id="2-准备工作"><a href="#2-准备工作" class="headerlink" title="2. 准备工作"></a>2. 准备工作</h2><h3 id="2-1-示例数据"><a href="#2-1-示例数据" class="headerlink" title="2.1 示例数据"></a>2.1 示例数据</h3><p><strong>示例数据下载地址</strong>：</p>
<p><strong>坚果云链接</strong>：<a target="_blank" rel="noopener" href="https://www.jianguoyun.com/p/DY4HWy4Q77P0ChixldYEIAA">https://www.jianguoyun.com/p/DY4HWy4Q77P0ChixldYEIAA</a> </p>
<p><strong>包含文件：</strong></p>
<ul>
<li><p><strong>shapefiles 文件</strong>，包括：<code>30省.cpg</code>，<code>30省.dbf</code>， <code>30省.prj</code>，<code>30省.sbn</code>，<code>30省.sbx</code>，<code>30省.shp</code>， <code>30省.shp.xml</code>，<code>30省.shx</code></p>
<p>8个文件缺一不可，需全部放在 Stata 当前工作路径之下</p>
</li>
<li><p><strong>pgdp_15.dta文件</strong> ，共包含一个变量，其中  <code>pgdp2015</code> 为 2015年30个省、市、自治区人均 gdp 数据</p>
</li>
</ul>
<h3 id="2-2-相关命令安装"><a href="#2-2-相关命令安装" class="headerlink" title="2.2 相关命令安装"></a>2.2 相关命令安装</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">ssc install 如下命令</span><br><span class="line"></span><br><span class="line">spwmatrix</span><br><span class="line">spmatrix </span><br><span class="line">spmat</span><br><span class="line">shp2dta </span><br><span class="line">spshape2dta</span><br><span class="line">mata</span><br><span class="line"></span><br><span class="line">//spmatrix 和 spshape2dta 需要 stata 15.0 及以上版本才能运行</span><br></pre></td></tr></table></figure>
<h3 id="2-3-mata-语言的基础用法"><a href="#2-3-mata-语言的基础用法" class="headerlink" title="2.3 mata 语言的基础用法"></a>2.3 mata 语言的基础用法</h3><h4 id="2-3-1-矩阵常规运算"><a href="#2-3-1-矩阵常规运算" class="headerlink" title="2.3.1 矩阵常规运算"></a>2.3.1 矩阵常规运算</h4><p>（1）矩阵乘法运算示意图及代码<br>$$\begin{bmatrix}1 &amp; 2 \3 &amp; 4 \end{bmatrix} \times \begin{bmatrix}2 &amp; 3 \4 &amp; 5 \end{bmatrix}&#x3D;\begin{bmatrix}1 \times 2+2 \times 4 &amp; 1 \times 3+2 \times 5 \3 \times 2+4 \times 4 &amp; 3 \times 3+4 \times 5 \end{bmatrix}$$</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// 矩阵 Wa 和 矩阵 Wb 相乘，得到矩阵 Wab</span><br><span class="line">mata	</span><br><span class="line">Wab = Wa * Wb</span><br><span class="line">Wab	</span><br><span class="line">end</span><br><span class="line">// mata 和 end 需要同时使用，表示进入 mata 语言</span><br></pre></td></tr></table></figure>
<p>（2）矩阵加法运算示意图及代码<br>$$\begin{bmatrix}1 &amp; 2 \3 &amp; 4 \end{bmatrix}+\begin{bmatrix}2 &amp; 3 \4 &amp; 5 \end{bmatrix}&#x3D;\begin{bmatrix}1+2 &amp; 2+3 \3+4 &amp; 4+5 \end{bmatrix}$$</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// 矩阵 Wa 和 矩阵 Wb 相加，得到矩阵 Wab</span><br><span class="line">mata	</span><br><span class="line">Wab = Wa + Wb</span><br><span class="line">Wab	</span><br><span class="line">end</span><br><span class="line">// mata 和 end 需要同时使用，表示进入 mata 语言</span><br></pre></td></tr></table></figure>
<h4 id="2-3-2-矩阵元素对元素运算"><a href="#2-3-2-矩阵元素对元素运算" class="headerlink" title="2.3.2 矩阵元素对元素运算"></a>2.3.2 矩阵元素对元素运算</h4><p>（1）元素对元素的运算示意图及代码</p>
<p>$$\begin{bmatrix}1 &amp; 2 \3 &amp; 4 \end{bmatrix} \times \begin{bmatrix}2 &amp; 3 \4 &amp; 5 \end{bmatrix}&#x3D;\begin{bmatrix}1 \times 2 &amp; 2 \times 3\3 \times 4&amp; 4 \times 5 \end{bmatrix}$$</p>
<p>即两个矩阵各元素对应相乘，$W_{ij}^a \times W_{ij}^b$</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// 矩阵 Wa 与矩阵 Wb 中的各元素对应相乘，得到矩阵 Wab</span><br><span class="line">mata	</span><br><span class="line">Wab = Wa ：* Wb</span><br><span class="line">Wab	</span><br><span class="line">end</span><br><span class="line">// “：” 加上 “+ - * /” ，便是元素对元素运算的符号</span><br></pre></td></tr></table></figure>
<h4 id="2-3-3-循环"><a href="#2-3-3-循环" class="headerlink" title="2.3.3 循环"></a>2.3.3 循环</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// for 循环语句</span><br><span class="line">	for (i=1; i&lt;=n; i++) &#123;</span><br><span class="line">  	     stmts  // stmts 可以理解为你打算循环的具体内容</span><br><span class="line">     &#125;</span><br><span class="line">// 表示 i 从 1 到 n 递增循环     </span><br></pre></td></tr></table></figure>
<h4 id="2-3-4-矩阵导入与导出"><a href="#2-3-4-矩阵导入与导出" class="headerlink" title="2.3.4 矩阵导入与导出"></a>2.3.4 矩阵导入与导出</h4><p><code>spmatrix matafromsp</code> 与<code>spmatrix spfrommata</code> 的基本语法如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">*-(1)矩阵导入 mata</span><br><span class="line">spmatrix matafromsp matamatrix matavec = spmatname</span><br><span class="line">*-(2)矩阵从 mata 导出</span><br><span class="line">spmatrix spfrommata spmatname = matamatrix matavec , normalize(normalize)</span><br></pre></td></tr></table></figure>
<ul>
<li><code>matamatrix</code> 储存在 mata 中矩阵的名字</li>
<li><code>spmatname</code> 储存在 Stata 中矩阵的名字</li>
<li><code>matavec</code> 表示唯一识别的一列向量，即观测对象的唯一 id</li>
<li><code>normalize(normalize)</code> 标准化选项，包括 none , row , spectral ，默认为 spectral 标准化</li>
</ul>
<h3 id="2-4-矢量图层获取、编辑与导入"><a href="#2-4-矢量图层获取、编辑与导入" class="headerlink" title="2.4 矢量图层获取、编辑与导入"></a>2.4 矢量图层获取、编辑与导入</h3><h4 id="2-4-1-矢量图层获取"><a href="#2-4-1-矢量图层获取" class="headerlink" title="2.4.1 矢量图层获取"></a>2.4.1 矢量图层获取</h4><p>标准地图可从 <a target="_blank" rel="noopener" href="http://bzdt.ch.mnr.gov.cn/index.html">标准地图服务系统网站</a> 下载，不过该网站不提供 SHP 格式的文件，仅能下载 JPG 格式与 EPS 格式的文件, SHP 格式的地图需要通过其他软件转换生成。对于经济学研究者来说，掌握矢量地图的制作方法并不是硬性要求，我们也可通过其他途径获得矢量地图，值得注意的是公开使用地图前需要送到自然资源主管部门审核。</p>
<h4 id="2-4-2-矢量图层编辑"><a href="#2-4-2-矢量图层编辑" class="headerlink" title="2.4.2 矢量图层编辑"></a>2.4.2 矢量图层编辑</h4><p> <strong>shapefiles</strong> 文件的编辑需要使用到 <strong>ArcGIS</strong> 软件，可网上搜索相关教程。一般来说，只要我们获得所研究区域的 <strong>shapefiles</strong> 文件，便可在 <strong>Stata</strong> 中进行如下操作。</p>
<h4 id="2-4-3-矢量图层导入-Stata"><a href="#2-4-3-矢量图层导入-Stata" class="headerlink" title="2.4.3 矢量图层导入 Stata"></a>2.4.3 矢量图层导入 Stata</h4><p>将 shapefile 文件导入 Stata 的两个常用命令分别是 <code>shp2dta</code>  和 <code>spshape2dta</code> ，后者为 Stata 空间计量官方命令。</p>
<p>（1）shp2dta 命令</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">shp2dta using 30省.shp, database(province30_dbf) ///</span><br><span class="line">    coordinates(province30_shp) ///</span><br><span class="line">    genid(geoid) gencentroids(zb) replace </span><br><span class="line">  </span><br><span class="line">use province30_dbf.dta, clear</span><br><span class="line">list 省 x_zb y_zb in 1/5</span><br><span class="line"></span><br><span class="line">     +------------------------------------+</span><br><span class="line">     |           省       x_zb       y_zb |</span><br><span class="line">     |------------------------------------|</span><br><span class="line">  1. |       北京市   116.4123   40.18554 |</span><br><span class="line">  2. |       天津市   117.3341   39.29343 |</span><br><span class="line">  3. |       河北省   116.1374   39.54777 |</span><br><span class="line">  4. |       山西省   112.2895   37.57175 |</span><br><span class="line">  5. | 内蒙古自治区   113.9221   44.08926 |</span><br><span class="line">     +------------------------------------+</span><br></pre></td></tr></table></figure>
<p>会新生成 province30_dbf.dta 和 province30_shp.dta 两个文件</p>
<p><strong>命令解释</strong></p>
<ul>
<li><code>30省.shp</code> 30省 shapefiles 文件名</li>
<li><code>database(province30_dbf)</code> 新生成的包含 <strong>30省.dbf</strong> 中信息的.dta文件，括号内为自定义名字</li>
<li><code>coordinates(province30_shp)</code> 新生成的包含 <strong>30省.shp</strong> 中信息的.dta文件，括号内为自定义名字</li>
<li><code>genid(geoid)</code> 为备选选项，生成一个 <strong>唯一 id</strong>，括号内为自定义名字</li>
<li><code>gencentroids(zb)</code> ：为备选选项，生成<strong>质心 x , y 坐标</strong>，括号内为自定义名字 </li>
<li><strong>注</strong>：对于距离矩阵或者经济距离矩阵来说，若 <code>.dta</code> 文件中已包含经纬度坐标和唯一 id ，则不需要 shapefiles 文件去生成矩阵，但是对于邻接矩阵来说，则必须需要 shapefiles 文件才能生成矩阵。因为，<strong>仅有经纬度数据是没办法判断两个区域是否相邻。</strong></li>
</ul>
<p>（2）spshape2dta 命令</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"> </span><br><span class="line">spshape2dta 30省.shp,replace</span><br><span class="line">    </span><br><span class="line">list 省 _CX _CY in 1/5</span><br><span class="line"></span><br><span class="line">     +--------------------------------------+</span><br><span class="line">     |           省         _CX         _CY |</span><br><span class="line">     |--------------------------------------|</span><br><span class="line">  1. |       北京市   116.41228   40.185543 |</span><br><span class="line">  2. |       天津市   117.33404   39.293426 |</span><br><span class="line">  3. |       河北省    116.1374    39.54777 |</span><br><span class="line">  4. |       山西省   112.28951   37.571746 |</span><br><span class="line">  5. | 内蒙古自治区    113.9221   44.089265 |</span><br><span class="line">     +--------------------------------------+</span><br></pre></td></tr></table></figure>

<p><code>spshape2dta</code> 会自动生成所需要的 <strong>唯一 id</strong> , <strong>经纬度坐标</strong>，同时会自动生成两个新文件，<strong>30省.dta</strong>  与 <strong>30省_shp.dta</strong></p>
<p><strong>命令解释</strong></p>
<ul>
<li><code>30省.dta</code> 新生成的包含 <strong>30省.dbf</strong> 中信息的 <code>.dta</code> 文件，命令自动生成的名字</li>
<li><code>30省_shp.dta</code> 新生成的包含 <strong>30省.shp</strong> 中信息的 <code>.dta</code> 文件，命令自动生成的名字</li>
<li><code> _CX 和 _CY</code> 分别为经纬度质心坐标</li>
</ul>
<p>（3）小结</p>
<p><code>shp2dta</code> 和 <code>spshape2dta</code> 均可将 shapefiles 文件导入为 Stata 可识别的 <code>.dta </code>文件，二者并无明显差别。如果打算采用 Stata 空间计量官方系列命令 SP 生成空间邻接矩阵并进行后续的回归分析，则建议采用 <code>spshape2dta</code>。后文主要使用<code>shp2dta</code> 生成的 <strong>province30_dbf.dta</strong> 和 <strong>province30_shp.dta</strong> 生成空间邻接矩阵。</p>
<h3 id="2-5-一颗好奇心"><a href="#2-5-一颗好奇心" class="headerlink" title="2.5 一颗好奇心"></a>2.5 一颗好奇心</h3><p>&amp;#x2764; <strong>好奇心</strong> 是科学工作者产生无穷的毅力和耐心的源泉——爱因斯坦</p>
<h2 id="3-空间权重矩阵的构建"><a href="#3-空间权重矩阵的构建" class="headerlink" title="3. 空间权重矩阵的构建"></a>3. 空间权重矩阵的构建</h2><h3 id="3-1-地理邻接矩阵"><a href="#3-1-地理邻接矩阵" class="headerlink" title="3.1 地理邻接矩阵"></a>3.1 地理邻接矩阵</h3><p>具体公式如下：</p>
<p>$$W_{ij}^{01}&#x3D;\begin{cases}0&amp; i与j不相邻\1 &amp;i与j相邻 \end{cases}$$</p>
<h4 id="3-1-1使用-spmat-生成地理邻接矩阵"><a href="#3-1-1使用-spmat-生成地理邻接矩阵" class="headerlink" title="3.1.1使用 spmat 生成地理邻接矩阵"></a>3.1.1使用 spmat 生成地理邻接矩阵</h4><p>（1）导入数据生成邻接矩阵</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">use province30_dbf.dta, clear</span><br><span class="line">spmat contiguity W01 using province30_shp, ///</span><br><span class="line">      id(geoid) rook normalize(row) replace    </span><br><span class="line">// warning: spatial-weighting matrix contains 1 island</span><br></pre></td></tr></table></figure>
<p><strong>注意</strong> 新生成的矩阵中存在 <strong>“孤岛”</strong>，即有一个观测值周围没有邻居，这就会导致矩阵中有一行元素全部为 0 ，会影响到后续的空间相关性检验与空间回归，所以我们需要<strong>手动或自动</strong>为它找一个邻居，这也是生成地理邻接矩阵最容易被大家忽视的一步。</p>
<p><strong>命令解释</strong></p>
<ul>
<li><code>contiguity</code> 生成邻接矩阵的选项</li>
<li><code>W01</code> 新生成的矩阵名字</li>
<li><code>province30_shp</code> 2.43 中生成的包含 30 省地理信息的 .dta 文件</li>
<li><code>id(geoid)</code> 2.43 中生成的唯一 id</li>
<li><code>rook</code> 默认为 queen 邻接，加 rook 选项后为 rook 邻接</li>
<li><code>normalize(row)</code> 行标准化，还有 minmax , spectral 两个选项</li>
</ul>
<p><strong>注：</strong><br><strong>rook 邻接</strong>：两个区域有一个面邻接则为 1，<strong>queen 邻接</strong>：两个区域有一个点邻接则为 1</p>
<p>（2）将矩阵保存成 <code>.spmat</code> 文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">spmat save W01 using W01.spmat, replace </span><br></pre></td></tr></table></figure>
<p>（3）将矩阵保存成 <code>.dta</code> 文件</p>
<p>常用空间命令当中所使用的矩阵均大多是 <strong>.dta 文件</strong> ，所以本步是将 <strong>W01.spmat</strong> 转化为 <strong>W01.dta</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">clear all</span><br><span class="line">spmat use W01 using W01.spmat , replace</span><br><span class="line">spmat getmatrix W01 W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save W01.dta ,replace</span><br></pre></td></tr></table></figure>
<p><strong>注：</strong> x*，即 x1-xn ，是按照原来唯一 id 即 (geoid) 顺序排列的。</p>
<p>（4）检查是否存在“孤岛”</p>
<p>stata 中提示 ：<strong>warning: spatial-weighting matrix contains 1 island</strong>，表明新生成的矩阵中存在 <strong>“孤岛”</strong> ，所以我们需要<strong>手动或自动</strong>为它找一个邻居。本文采取手动方式，感兴趣的朋友也可 <code>help spwmatfill</code> 研究如何自动生成。</p>
<p><strong>注</strong>：<code>spwmatfill</code>仅适合由 GeoDa 软件生成的 .gal 格式的空间邻接矩阵</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">*-海南 id：21 是孤岛，根据文献手动为其添加一个邻居 广东 id：19</span><br><span class="line">replace x19 = 1 in 21</span><br><span class="line"></span><br><span class="line">*-如果广东成为海南的邻居，那么广东的邻居数也应该由4个增加至5个</span><br><span class="line">replace x13 = 0.2 in 19</span><br><span class="line">replace x14 = 0.2 in 19</span><br><span class="line">replace x18 = 0.2 in 19</span><br><span class="line">replace x20 = 0.2 in 19</span><br><span class="line">replace x21 = 0.2 in 19</span><br><span class="line">save W01.dta ,replace</span><br></pre></td></tr></table></figure>
<p>至此，我们成功生成出采用 <strong>rook 邻接并经过行标准化后的地理邻接矩阵</strong> <code>W01</code></p>
<h4 id="3-1-2-其他生成地理邻接矩阵的命令"><a href="#3-1-2-其他生成地理邻接矩阵的命令" class="headerlink" title="3.1.2 其他生成地理邻接矩阵的命令"></a>3.1.2 其他生成地理邻接矩阵的命令</h4><p>除 <code>spmat</code> 外， <code>spmatrix</code> 与 <code>spwmatrix</code> 也可生成地理邻接矩阵，矩阵保存及导出方法类似，故不再详细说明，本文仅列出这两个命令的核心用法及注意事项。与此同时，本文提供一种导入 <strong>GeoDa 软件</strong> 所生成的权重矩阵的方法。</p>
<p>(1) <strong>spmatrix</strong> 生成地理邻接矩阵的核心代码</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">use 30省.dta, clear // 2.4.3(2)中 spshape2dta 生成的文件</span><br><span class="line">spset //告诉 stata 是空间数据，使用 spmatrix 必要步骤</span><br><span class="line">spset, modify coordsys(latlong, kilometers) //修改单位参考系</span><br><span class="line">spmatrix create contiguity W01_2,normalize(row) replace</span><br><span class="line">   // weighting matrix in W01_2 contains 1 island</span><br><span class="line">spmatrix export W01_2 using W01_2.txt //导出矩阵</span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<ul>
<li><code>W01_2</code> 新生成的自定义矩阵名字</li>
<li><code>normalize(row)</code> row 为行标准化，默认为 spectral 标准化，其他标准化选项 minmax , none</li>
</ul>
<p><strong>注：</strong> 采用<code>spshape2dta</code>所生成的<code> 30省.dta 文件</code> ，也提示该矩阵存在 <strong>“孤岛“</strong>。</p>
<p>(2) <strong>spwmatrix</strong> 生成地理邻接矩阵的核心代码</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">* help spwmatrix</span><br><span class="line">spwmatrix gecon varlist [if] [in], wname(wght_name) ///</span><br><span class="line">      wtype(bin) cart r(#) dband(numlist) ///</span><br><span class="line">      alpha(#) knn(#) econvar(varname1) beta(#) Other_options</span><br><span class="line">          </span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<p><code>wtype(bin)</code> bin 代表生成邻接矩阵的选项</p>
<p>更多有关 <code>spwmatrix</code> 的解释可参考<a target="_blank" rel="noopener" href="https://www.lianxh.cn/news/919826ca0da88.html">空间权重矩阵的构建-潘星宇</a></p>
<p>(3) <strong>spwmatrix</strong> 导入 <strong>GeoDa软件</strong> 所生成的地理邻接矩阵的核心代码</p>
<p><strong>GeoDa 软件</strong> 作为常用空间统计分析软件之一，其中很方便的一个功能便是<strong>生成空间权重矩阵</strong>，但是 **“生成容易，导入 Stata 难”**，不过 **“世上无难事，只怕有心人”**，我们可以通过 <code>spwmatrix</code> 导入 <strong>GeoDa 软件</strong>所生成的矩阵并转换成<code> .dta 文件</code>。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">spwmatrix import using 30省.gal,wname(W01_3) row ///</span><br><span class="line">     xport(W01_3, dat) replace</span><br><span class="line">     svmat W01_3</span><br><span class="line">     matname W01_3 x*</span><br><span class="line">     save W01_3.dta   </span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<ul>
<li><code>30省.gal</code> <strong>GeoDa 软件</strong> 所生成的地理邻接矩阵文件</li>
<li><code>wname(W01_3)</code> W01_3 为自定义名字</li>
<li><code>row</code> 行标准化</li>
<li><code>svmat</code> 将矩阵导入到变量中，详见 help 文件</li>
<li><code>matname</code>  为矩阵的行列改名</li>
</ul>
<h3 id="3-2-广义”相邻”矩阵"><a href="#3-2-广义”相邻”矩阵" class="headerlink" title="3.2 广义”相邻”矩阵"></a>3.2 广义”相邻”矩阵</h3><p>广义”相邻”矩阵的一个例子：</p>
<p>全国30个省、市、自治区可划分东中西三大区域，生成一列地区虚拟变量 <strong>region</strong>，其中东部为 1,中部为 2，西部为 3。如果两个省属于相同区域（即 region 相同）则 $W_{ij}$ 为1，如果两个省份分属不同区域（即 region 不同）则 $W_{ij}$ 为 0。</p>
<p>具体公式如下：</p>
<p>$$W_{ij}^s&#x3D;\begin{cases}0&amp; i与j 不属于同一区域\1 &amp;i与j 属于同一区域 \end{cases}$$</p>
<p>按此规则所生成矩阵的命令如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">use province30_dbf.dta,clear</span><br><span class="line">	</span><br><span class="line">*-生成东中西虚拟变量，其中 1 为东部，2 为中部，3 为西部</span><br><span class="line">	</span><br><span class="line">gen  region=1</span><br><span class="line">replace region=2 if geoid==4 | geoid==7 | geoid==8  | geoid==12|  ///</span><br><span class="line">	                geoid==14 | geoid==16 | geoid==17 | geoid==18</span><br><span class="line">	</span><br><span class="line">replace region=3 if geoid==5 | geoid==20 | geoid==22  | geoid==23|  ///</span><br><span class="line">	                geoid==24 | geoid==25 | geoid==26 | geoid==27|  ///</span><br><span class="line">		            geoid==28 | geoid==29 | geoid==30</span><br><span class="line">save province30_dbf_region.dta,replace</span><br><span class="line"></span><br><span class="line">*-生成广义&quot;相邻&quot;矩阵</span><br><span class="line">use province30_dbf_region.dta,clear</span><br><span class="line">spwmatrix socio region, wname(Wsoc01) wtype(socnet)  ///</span><br><span class="line">          idvar(geoid) xport(Wsoc01,txt) replace</span><br><span class="line">clear all</span><br><span class="line">spmat import Wsoc01 using &quot;Wsoc01.txt&quot;, replace</span><br><span class="line">spmat getmatrix Wsoc01 W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save Wsoc01.dta ,replace</span><br><span class="line"></span><br><span class="line">注：也可通过 spmat 命令对矩阵行标准化后再导出</span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<ul>
<li><code>spwmatrix socio</code> 社会网络矩阵生成命令</li>
<li><code>region</code> province30_dbf_region.dta 中一个虚拟变量，东部为 1，中部为 2，西部为 3</li>
<li><code>wname(Wsoc01)</code> 自定义的矩阵名字</li>
<li><code>wtype(socnet)</code> 生成矩阵的类型选社会网络矩阵</li>
<li><code>idvar(id)</code> 唯一 id </li>
<li><code>xport(Wsoc01,txt)</code> 导出成 <strong>.txt</strong> 文件，**.txt 文件<strong>最大的好处就在于几乎每一个空间计量命令都可以识别，从而可以实现</strong>跨命令操作**。</li>
<li><code>getmata</code> 可将矩阵导入到数据中，从而生成相应的 <strong>.dta 文件</strong></li>
</ul>
<p><strong>最终结果解读</strong>：1 代表着两个省份属于同一区域，0 代表着两个省份属于不同区域	</p>
<h3 id="3-3-地理距离矩阵"><a href="#3-3-地理距离矩阵" class="headerlink" title="3.3 地理距离矩阵"></a>3.3 地理距离矩阵</h3><p>Stata 生成地理距离矩阵的命令主要有 <code>spwmatrix</code> 与 <code>spmatrix</code>, 同时也可以采用 <code>spmat</code> 命令导入 <strong>GeoDa 软件</strong>所生成的地理距离矩阵，本文主要基于 <code>spwmatrix</code> 生成地理距离矩阵、地理距离平方矩阵，并保存成相应格式文件。</p>
<h4 id="3-3-1-spwmatrix-生成地理距离矩阵"><a href="#3-3-1-spwmatrix-生成地理距离矩阵" class="headerlink" title="3.3.1 spwmatrix 生成地理距离矩阵"></a>3.3.1 spwmatrix 生成地理距离矩阵</h4><p>对于反距离矩阵与反距离平方矩阵来说，最容易被忽视的就是距离的<strong>单位</strong>。<strong>kilometers</strong> 和 <strong>miles</strong> 会产生不同的结果，<code>spwmatrix</code> 默认的距离单位是 <strong>kilometers</strong></p>
<p>(1)反地理距离矩阵</p>
<p>具体公式如下：</p>
<p>$$W_{ij}^d&#x3D;\begin{cases}{\frac{1}{d_{ij}}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">clear all</span><br><span class="line">use province30_dbf.dta,clear</span><br><span class="line">spwmatrix gecon  y_zb x_zb , wn(Wd) wtype(inv) ///</span><br><span class="line">          alpha(1) xport(Wd,txt) replace // 加上 row，即可对矩阵行标准化</span><br><span class="line">clear all</span><br><span class="line">spmat import Wd using &quot;Wd.txt&quot;, replace</span><br><span class="line">spmat getmatrix Wd W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save Wd.dta ,replace</span><br><span class="line">use Wd.dta ,clear</span><br></pre></td></tr></table></figure>


<p><strong>命令解释</strong></p>
<ul>
<li><code>province30_dbf.dta</code> 2.43 中生成的包含原 shapefiles 文件图层信息的 .dta 文件</li>
<li><code>y_zb x_zb</code> 经度，纬度 ,一定要按照这个顺序排列</li>
<li><code>wn(Wd)</code> 新生成的矩阵的名字 </li>
<li><code>wtype(inv)</code> inv 选项为距离衰减矩阵（反距离矩阵）</li>
<li><code>alpha(1)</code> 默认为 1 ,若为 2 则生成的是反距离平方矩阵</li>
<li><code>xport(Wd,txt)</code>生成矩阵的同时，导出成 .txt文件 ，生成嵌套矩阵时会有大用处 </li>
<li><code>row </code> 加上则为行标准化</li>
</ul>
<p><strong>注：</strong> 其余选项均为默认值，如有特殊需求，请参考<code>help文件</code></p>
<p>(2)反地理距离平方矩阵<br>具体公式如下：<br>$$W_{ij}^d&#x3D;\begin{cases}{\frac{1}{d_{ij}^2}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">clear all</span><br><span class="line">use province30_dbf.dta,clear</span><br><span class="line">spwmatrix gecon  y_zb x_zb , wn(Wd2) wtype(inv) ///</span><br><span class="line">          alpha(2) xport(Wd2,txt) replace // 加上 row，即可对矩阵行标准化</span><br><span class="line">clear all</span><br><span class="line">spmat import Wd2 using &quot;Wd2.txt&quot;, replace</span><br><span class="line">spmat getmatrix Wd2 W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save Wd2.dta ,replace</span><br><span class="line">use Wd2,clear</span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong>与反距离矩阵解释相同，故不再赘述。</p>
<h4 id="3-3-2-其他生成地理距离矩阵的命令"><a href="#3-3-2-其他生成地理距离矩阵的命令" class="headerlink" title="3.3.2 其他生成地理距离矩阵的命令"></a>3.3.2 其他生成地理距离矩阵的命令</h4><p>(1)spmatrix 命令生成反距离矩阵</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">clear all</span><br><span class="line">spshape2dta 30省.shp,replace </span><br><span class="line">use 30省.dta,clear</span><br><span class="line">spset, modify coordsys(latlong, kilometers) //更改单位成kilometers</span><br><span class="line">spmatrix create idistance Wind,normalize(none) replace //未经过标准化	</span><br><span class="line">spmatrix export Wind using Wind.txt,replace //导出成.txt文件</span><br><span class="line"></span><br><span class="line">clear all</span><br><span class="line">spmat import Wind using &quot;Wind.txt&quot;, replace</span><br><span class="line">spmat getmatrix Wind W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save Wind.dta ,replace</span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<ul>
<li><code>spset</code> 将数据定义为空间数据</li>
<li><code>modify coordsys(latlong, kilometers)</code> 将单位更改为 kilometers，默认单位为 plana ，备选中还有 miles</li>
<li><code>spmatrix create idistance</code> 生成反距离矩阵的命令</li>
<li><code>normalize(none)</code> 是否进行标准化选项，如行标准化，则替换为 row</li>
</ul>
<p><strong>注：</strong> <code>spmatrix</code> 无法直接生成反距离平方矩阵，<code>spwmatrix</code>与<code>spmatrix</code>两种命令生成的反距离矩阵近似相等（小数点后三位保持一致）。</p>
<p>(2)导入<strong>GeoDa 软件</strong>所生成的反距离距离矩阵</p>
<p>借用 <code>spmat</code> 导入<code>.gwt文件</code>，并生成 <code>.dta</code>文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">spmat import A using 30省.gwt, geoda replace//导入geoda生成的距离矩阵，命名为A</span><br><span class="line">spmat getmatrix A W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save 30省.dta, replace</span><br></pre></td></tr></table></figure>
<ul>
<li><code>30省.gwt</code> GeoDa 软件生成的反距离矩阵文件</li>
<li><code>GeoDa软件</code> 可在软件内自行选取<strong>反距离矩阵</strong>或<strong>反距离平方矩阵</strong>，同时可以手动更改<strong>距离单位</strong></li>
</ul>
<p><strong>注：</strong> 第二行与第三行代码连用可以生成 x1，x2…x30 存放着刚刚导入进来的反距离矩阵， x1，x2…x30 的排列顺序 与 shapefiles 文件生成矩阵时所用的唯一 id 顺序一样。</p>
<h3 id="3-4-经济距离矩阵"><a href="#3-4-经济距离矩阵" class="headerlink" title="3.4 经济距离矩阵"></a>3.4 经济距离矩阵</h3><p>经济距离的形式有很多种，本文以经济变量<strong>人均 gdp</strong> 构造经济距离矩阵，具体公式如下：</p>
<p>$$W_{ij}^e&#x3D;\begin{cases}{\frac{1}{|PGDP_i-PGDP_j|}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>除此之外，也可以通过<strong>更换经济变量</strong>或<strong>改变计算公式</strong>来构造适合您研究的经济距离矩阵，本文以常见的<strong>人均 gdp 距离矩阵</strong>为例，提供生成经济距离矩阵的代码。在此代码之下，稍作调整，便可生成其他类型的经济距离矩阵。</p>
<p>（1）导入、合并经济数据</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">use province30_dbf.dta ,clear </span><br><span class="line">rename 省 province</span><br><span class="line">merge 1:1 province using &quot;pgdp_15.dta&quot;</span><br><span class="line">sort geoid //按照geoid排序</span><br><span class="line">drop _merge //删掉多余的值</span><br><span class="line">save province30_pgdp15.dta,replace</span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<ul>
<li><code>province30_dbf.dta</code> 2.43 中生成的带有<strong>经纬度坐标</strong>的文件</li>
<li><code>pgdp_15.dta</code> 带有 2015年 <strong>人均 gdp</strong> 的文件</li>
<li><code>merge</code> 将两个文件合并，更多请参考 <code>help 文件</code></li>
</ul>
<p>（2）生成经济距离矩阵</p>
<p>本文是以 <strong>2015 年的人均 gdp</strong> 作为经济变量，考虑到在后续空间相关性分析及空间回归等命令中所使用的矩阵均为<strong>截面矩阵</strong>，只取一年经济数据或有不妥，所以文献中常用的一个办法就是对若干年份的人均 gdp 求<strong>平均值</strong>。本文旨在提供方法，故仅以 <strong>2015 年的人均 gdp</strong> 为例生成经济距离矩阵。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">clear all</span><br><span class="line">use province30_pgdp15.dta,clear </span><br><span class="line">tomata pgdp2015 </span><br><span class="line">mata</span><br><span class="line"></span><br><span class="line">     W = J(30,30,0)</span><br><span class="line">     id = 1::30</span><br><span class="line">     for (i=1; i&lt;=length(pgdp2015);i++) &#123;</span><br><span class="line">             for (j=1; j&lt;=length(pgdp2015);j++) &#123;</span><br><span class="line"></span><br><span class="line">            wi=pgdp2015[i]  ;wj=pgdp2015[j]</span><br><span class="line">                if (i!=j)</span><br><span class="line">            W[i,j]=1/abs(wi-wj)</span><br><span class="line">         </span><br><span class="line">             &#125;                </span><br><span class="line">     &#125;</span><br><span class="line">end </span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<ul>
<li><code>tomata pgdp2015</code> 将 pgdp2015 导入 mata 中</li>
<li><code>W = J(30,30,0)</code> 生成30行，30列，元素全部为 0 的矩阵</li>
<li><code>id = 1::30 </code> 生成一列 id</li>
<li><code>i&lt;=length(pgdp2015);i++)</code> length()表示循环次数，本文以变量 pgdp2015 的观测数作为循环次数，故表示为 i 从 1 到 30 递增循环</li>
<li><code>if (i!=j)</code> 如果 i 与 j 不相等，便进行下述循环</li>
<li><code>W[i,j]=1/abs(wi-wj)</code> 矩阵计算公式的 Stata 表达</li>
</ul>
<p><strong>注：</strong> 在 <strong>do files</strong> 下 <code>mata</code> 和 <code>end</code>之间的内容，需要同时运行。</p>
<p>（3）导出生成的矩阵到 stata 中并保存成相应文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">*语法格式为 spmatrix spfrommata spmatname = matamatrix matavec [, options]</span><br><span class="line"></span><br><span class="line">spmatrix spfrommata We_2015 = W id ,normalize(none) </span><br><span class="line">spmatrix dir</span><br><span class="line"></span><br><span class="line">------------------------------------------------------------------------</span><br><span class="line">   Weighting matrix name           N x N      Type         Normalization</span><br><span class="line">------------------------------------------------------------------------</span><br><span class="line">                 We_2015         30 x 30    custom           none</span><br><span class="line">------------------------------------------------------------------------</span><br><span class="line"></span><br><span class="line">spmatrix export We_2015 using We_2015.txt , replace</span><br><span class="line">clear</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save We_2015.dta ,replace</span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<ul>
<li><code>spmatrix spfrommata</code> 从 mata 中将矩阵导入 </li>
<li><code>stataspmatname</code> 新生成 stata 矩阵的自定义名字，如 <code>We_2015</code></li>
<li><code>matamatrix</code> 原始 mata 矩阵的名字，如 <code>W</code></li>
<li><code>normalize(none)</code> 标准化选项，none 为不标准化，row 为行标准化</li>
</ul>
<p><strong>注：</strong> 这里之所以不对新生成的矩阵进行<strong>行标准化</strong>，是因为后续<strong>地理经济嵌套矩阵</strong>的生成会使用到这个矩阵。根据您的研究需要，可自由调整标准化选项。</p>
<h3 id="3-5-地理经济嵌套矩阵（相加）"><a href="#3-5-地理经济嵌套矩阵（相加）" class="headerlink" title="3.5 地理经济嵌套矩阵（相加）"></a>3.5 地理经济嵌套矩阵（相加）</h3><p>经过上述几步，我们已经生成了常见的三种空间权重矩阵，分别是<strong>地理邻接矩阵</strong> <code>W01</code>，<strong>反地理距离矩阵</strong> <code>Wd</code> ，<strong>反地理距离平方矩阵</strong> <code>Wd2</code>，<strong>经济地理矩阵</strong> <code>We_2015</code>，以及<strong>广义”相邻“矩阵</strong> <code>Wsoc01</code> 。</p>
<p>从这一小节开始，我们便以 <strong>2.3 mata语言的基础用法</strong> 中提供的代码为基础，进行矩阵运算，以期生成我们想要的空间权重矩阵，诚如上文所提，<code>.txt文件</code> 能够在不同空间命令中 <strong>”自由穿梭“</strong> ，故在使用上述命令生成空间权重矩阵过程中，均附带导出生成<code>.txt文件</code>文件，如 <code>We_2015.txt</code>。</p>
<p>后续空间权重矩阵的生成便仰仗我们的<code>.txt文件</code> 与 <code>mata</code> 两位兄弟！</p>
<p>（1）地理经济嵌套矩阵（相加）的生成</p>
<p>具体公式如下：</p>
<p>$$W_{ij}^{de}&#x3D;\begin{cases}{\alpha \times W_{ij}^{d}+(1-\alpha) \times W_{ij}^{e}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>为了简便，本文将<strong>地理距离矩阵</strong>和<strong>经济距离矩阵</strong>的权重均设置为 <strong>0.5</strong>，根据研究需要，您可设置不同比例权重。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">spmatrix import Wd using Wd.txt ,replace</span><br><span class="line">spmatrix import We using We_2015.txt ,replace</span><br><span class="line">spmatrix matafromsp W1 id = Wd</span><br><span class="line">spmatrix matafromsp W2 id = We</span><br><span class="line">mata</span><br><span class="line">        W12 = 0.5:*W1 :+ 0.5:*W2</span><br><span class="line">end</span><br><span class="line">spmatrix spfrommata Wde = W12 id, normalize(none)</span><br></pre></td></tr></table></figure>
<p><strong>思路</strong>： <strong>首先</strong>，借助 <code>spmatrix</code> 导入两个 <code>.txt</code>格式的矩阵，分别是上几步所生成的<strong>反距离矩阵</strong>及<strong>经济距离矩阵</strong>；<strong>其次</strong>，通过 <code>spmatrix matafromsp</code> 将矩阵导入 <strong>mata</strong> 中；<strong>然后</strong>，在 <strong>mata</strong> 中进行矩阵运算； <strong>最后</strong>，从 <strong>mata</strong> 中，将计算好的矩阵导出到 <strong>stata</strong> 中。</p>
<p><strong>注</strong>： 以上矩阵运算均为<strong>元素对元素运算(element_by_element)</strong></p>
<p>（2）删除多余缓存矩阵</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">mata: mata drop W12 W1 W2 // 删掉 mata 中暂存的矩阵</span><br><span class="line">spmatrix drop  Wd</span><br><span class="line">spmatrix drop  We   // 删掉 spmatrix 中暂存的矩阵</span><br><span class="line">spmatrix dir // 矩阵展示</span><br><span class="line">------------------------------------------------------------------------</span><br><span class="line">   Weighting matrix name           N x N      Type         Normalization</span><br><span class="line">------------------------------------------------------------------------</span><br><span class="line">                     Wde         30 x 30    custom           none</span><br><span class="line">------------------------------------------------------------------------</span><br></pre></td></tr></table></figure>
<p>（3）导出、保存矩阵</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">spmatrix export Wde using Wde_2015.txt,replace</span><br><span class="line">clear all</span><br><span class="line">spmat import Wde_2015 using &quot;Wde_2015.txt&quot;, replace</span><br><span class="line">spmat getmatrix Wde_2015 W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save Wde_2015.dta ,replace</span><br></pre></td></tr></table></figure>
<p>有关导出及保存原理，前文已解释，便不再赘述。</p>
<p>需要注意一点的是，凡是涉及到<strong>经济变量</strong>的矩阵，到底是选取<strong>某一年的经济变量</strong>，还是选取<strong>多年经济变量的平均值</strong>，这些细节，需要您根据研究内容做出适当选择。不过生成权重矩阵的方法是一致的。</p>
<h3 id="3-6-地理经济嵌套矩阵（相乘）"><a href="#3-6-地理经济嵌套矩阵（相乘）" class="headerlink" title="3.6 地理经济嵌套矩阵（相乘）"></a>3.6 地理经济嵌套矩阵（相乘）</h3><p>具体公式如下：</p>
<p>$$W_{ij}^{de}&#x3D;\begin{cases}{W_{ij}^{d} \times W_{ij}^{e}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>（1）采用 mata 手动生成地理经济嵌套矩阵（相乘）</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">*(1)生成矩阵</span><br><span class="line"></span><br><span class="line">spmatrix import Wd using Wd.txt ,replace</span><br><span class="line">spmatrix import We using We_2015.txt ,replace</span><br><span class="line">spmatrix matafromsp W1 id = Wd</span><br><span class="line">spmatrix matafromsp W2 id = We</span><br><span class="line">mata</span><br><span class="line"></span><br><span class="line">    W12 = W1 :* W2</span><br><span class="line"></span><br><span class="line">end</span><br><span class="line"></span><br><span class="line">*(2)删除多余矩阵</span><br><span class="line">spmatrix spfrommata Wde = W12 id, normalize(none)       </span><br><span class="line">mata: mata drop W12 W1 W2 // 删掉 mata 中暂存的矩阵</span><br><span class="line">spmatrix drop  Wd</span><br><span class="line">spmatrix drop  We   // 删掉 spmatrix 中暂存的矩阵</span><br><span class="line">spmatrix dir // 矩阵展示</span><br><span class="line">------------------------------------------------------------------------</span><br><span class="line">   Weighting matrix name           N x N      Type         Normalization</span><br><span class="line">------------------------------------------------------------------------</span><br><span class="line">                     Wde         30 x 30    custom           none</span><br><span class="line">------------------------------------------------------------------------</span><br><span class="line"></span><br><span class="line">*(3)导出矩阵</span><br><span class="line">spmatrix export Wde using Wde_2015_2.txt,replace</span><br><span class="line">clear all</span><br><span class="line">spmat import Wde_2015_2 using &quot;Wde_2015_2.txt&quot;, replace</span><br><span class="line">spmat getmatrix Wde_2015_2 W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save Wde_2015_2.dta ,replace</span><br></pre></td></tr></table></figure>

<p>（2）采用 spwmatrix 自动生成地理经济嵌套矩阵（相乘）</p>
<p><code>spwmatrix</code> 所采用的计算公式如下：</p>
<p>$$W_{ij}^{de}&#x3D;\begin{cases}{\frac{1}{|PGDP_i-PGDP_j+1|}\times e^{-\beta\times{d_{ij}}}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>$\beta$ 默认为1, $PGDP_{i}$ 为地区 i 的人均 GDP ，$PGDP_{j}$ 为地区 j 的人均 GDP , $d_{ij}$ 为地区 i 和地区 j 之间的距离。</p>
<p>具体代码如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">*(1)生成矩阵</span><br><span class="line"></span><br><span class="line">clear all</span><br><span class="line">use province30_pgdp15.dta,clear</span><br><span class="line">spwmatrix gecon  x_zb y_zb, wn(Wecon_2015) wtype(invecon) cart ///</span><br><span class="line">          econvar(pgdp2015)  xport(Wecon_2015,txt) replace</span><br><span class="line"></span><br><span class="line">*(2)导出矩阵</span><br><span class="line"></span><br><span class="line">clear all</span><br><span class="line">spmat import Wecon_2015 using &quot;Wecon_2015.txt&quot;,replace</span><br><span class="line">spmat getmatrix Wecon_2015 W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save Wecon_2015.dta ,replace</span><br><span class="line">use Wecon_2015,clear</span><br></pre></td></tr></table></figure>
<p><strong>命令解释</strong></p>
<ul>
<li><code>province30_pgdp15.dta</code> 带有经纬度及经济变量数据的文件</li>
<li><code>spwmatrix gecon- </code> 矩阵生成命令</li>
<li><code>x_zb y_zb </code> 经纬度坐标</li>
<li><code>wn(Wecon_2015)</code> 自定义矩阵名字</li>
<li><code>wtype(invecon)</code> 选择生成反经济距离选项</li>
<li><code>cart</code> 表示经纬度坐标采用笛卡尔坐标</li>
<li><code>econvar(pgdp2015)</code> 声明 pgdp2015 这一列代表经济变量</li>
<li><code>xport(Wecon_2015,txt)</code> 导出成 .txt 文件</li>
</ul>
<h3 id="3-7-传统引力模型矩阵"><a href="#3-7-传统引力模型矩阵" class="headerlink" title="3.7 传统引力模型矩阵"></a>3.7 传统引力模型矩阵</h3><p>具体公式如下：</p>
<p>$$W_{ij}^{de}&#x3D;\begin{cases}{\frac{PGDP_i \times PGDP_j}{d_{ij}^2}} &amp; i\neq j\0 &amp; i &#x3D;j \end{cases}$$</p>
<p>$PGDP_{i}$ 为地区 i 的人均 GDP ，$PGDP_{j}$ 为地区 j 的人均 GDP , $d_{ij}$ 为地区 i 和地区 j 之间的距离。</p>
<p><strong>思路</strong>：分别生成<strong>反距离平方矩阵</strong>和 <strong>pgdp 两两相乘矩阵</strong>，然后两个矩阵再相乘。</p>
<p>(1) 生成 pgdp 两两相乘矩阵：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">*（1）矩阵计算</span><br><span class="line"></span><br><span class="line">clear all</span><br><span class="line">use province30_pgdp15.dta,clear </span><br><span class="line">tomata pgdp2015 </span><br><span class="line">mata</span><br><span class="line"> </span><br><span class="line">   W = J(30,30,0)</span><br><span class="line">   id = 1::30</span><br><span class="line">   for (i=1; i&lt;=length(pgdp2015);i++) &#123;</span><br><span class="line">      for (j=1; j&lt;=length(pgdp2015);j++) &#123;</span><br><span class="line">                </span><br><span class="line">            Wi=pgdp2015[i]      ;Wj=pgdp2015[j]</span><br><span class="line">                if (i!=j)</span><br><span class="line">            W[i,j]=Wi*Wj       </span><br><span class="line">      &#125;                </span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">end </span><br><span class="line"></span><br><span class="line">*（2）将 mata 生成的矩阵导入 Stata 中</span><br><span class="line"></span><br><span class="line">spmatrix spfrommata We2_2015 = W id ,normalize(none) </span><br><span class="line">spmatrix dir</span><br><span class="line">spmatrix export We2_2015 using We2_2015.txt , replace</span><br><span class="line">  </span><br><span class="line">*（3）导出成 dta 文件  </span><br><span class="line"></span><br><span class="line">clear</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save We2_2015.dta ,replace</span><br><span class="line">use We2_2015.dta,clear</span><br></pre></td></tr></table></figure>

<p>(2) 生成传统引力模型矩阵</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">spmatrix import Wd using Wd2.txt ,replace</span><br><span class="line">spmatrix import We using We_2015.txt ,replace</span><br><span class="line">spmatrix matafromsp W1 id = Wd</span><br><span class="line">spmatrix matafromsp W2 id = We</span><br><span class="line">mata</span><br><span class="line">W12 = W1 :* W2</span><br><span class="line">end</span><br><span class="line">spmatrix spfrommata Wde = W12 id, normalize(none)</span><br><span class="line">	</span><br><span class="line">mata: mata drop W12 W1 W2 //删掉mata中暂存的矩阵</span><br><span class="line">spmatrix drop  Wd</span><br><span class="line">spmatrix drop  We   //删掉spmatrix中暂存的矩阵</span><br><span class="line">spmatrix dir // 矩阵展示</span><br><span class="line">	</span><br><span class="line">spmatrix export Wde using Wde2_2015.txt,replace</span><br><span class="line">clear all</span><br><span class="line">spmat import Wde2_2015 using &quot;Wde2_2015.txt&quot;, replace</span><br><span class="line">spmat getmatrix Wde2_2015 W</span><br><span class="line">getmata (x*)=W</span><br><span class="line">save Wde2_2015.dta ,replace</span><br><span class="line">use Wde2_2015,clear</span><br></pre></td></tr></table></figure>
<p>有关代码的解释，前文已经叙述，故不再赘述。</p>
<p><strong>注意</strong>一个细节，构造复合矩阵的两个矩阵需要<strong>不进行进标准化</strong>，等复合矩阵构造完毕后，再对复合矩阵进行相应标准化。</p>
<h3 id="3-8-天马行空的矩阵"><a href="#3-8-天马行空的矩阵" class="headerlink" title="3.8 天马行空的矩阵"></a>3.8 天马行空的矩阵</h3><p>充分发挥我们的想象力，我们便可生成更多 <strong>“天马行空”</strong> 的空间权重矩阵，一个 <strong>“恰到好处”</strong> 的空间权重矩阵，会在我们研究过程中起到 <strong>“画龙点睛”</strong> 的作用。</p>
<p>比如，我们还可以构造<strong>地理经济嵌套矩阵（相加、相乘）</strong>，<strong>反距离平方矩阵的相关组合</strong>，<strong>加权引力模型矩阵</strong>等等。</p>
<h2 id="4-结语"><a href="#4-结语" class="headerlink" title="4. 结语"></a>4. 结语</h2><p>至此，总结一下本文所生成的空间权重矩阵：</p>
<ul>
<li><strong>地理邻接矩阵：</strong> <code>W01</code></li>
<li><strong>广义”相邻“矩阵：</strong> <code>Wsoc01</code> </li>
<li><strong>反地理距离矩阵：</strong> <code>Wd</code> </li>
<li><strong>反地理距离平方矩阵：</strong> <code>Wd2</code></li>
<li><strong>经济地理矩阵：</strong> <code>We_2015</code></li>
<li><strong>地理经济嵌套矩阵（相加）：</strong> <code>Wde_2015</code></li>
<li><strong>地理经济嵌套矩阵（相乘）：</strong> <code>Wde_2015_2</code>，<code>Wecon_2015</code></li>
<li><strong>引力模型矩阵：</strong> <code>Wde2_2015</code></li>
</ul>
<p>在后续空间相关性分析、模型检验及回归分析中，<strong>不同命令</strong>对于空间权重矩阵格式的要求不尽相同，不过大多数命令都可以支持识别 <code>.txt文件</code>。</p>
<p>建议大家在研究过程中<strong>灵活使用各种命令</strong> ，达到 “<strong>取其精华</strong>”的效果。</p>
<p><strong>参考资料</strong></p>
<ul>
<li>张学良.中国交通基础设施促进了区域经济增长吗——兼论交通基础设施的空间溢出效应[J].中国社会科学,2012(03):60-77+206.</li>
<li>邵帅,李欣,曹建华,杨莉莉.中国雾霾污染治理的经济政策选择——基于空间溢出效应的视角[J].经济研究,2016,51(09):73-88.</li>
<li><a target="_blank" rel="noopener" href="https://www.lianxh.cn/news/919826ca0da88.html">空间权重矩阵的构建-潘星宇</a></li>
<li>杨海生老师的空间计量公开课</li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/star8kr/tags/Stata/" rel="tag"># Stata</a>
              <a href="/star8kr/tags/%E7%A9%BA%E9%97%B4%E8%AE%A1%E9%87%8F/" rel="tag"># 空间计量</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/star8kr/2022/07/02/%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E7%BD%91%E7%AB%99/" rel="prev" title="手把手教你|免费搭建个人网站（Hexo+Gitee）">
      <i class="fa fa-chevron-left"></i> 手把手教你|免费搭建个人网站（Hexo+Gitee）
    </a></div>
      <div class="post-nav-item">
    <a href="/star8kr/2023/04/18/Stata%E5%AD%A6%E4%B9%A0/" rel="next" title="Stata 学习">
      Stata 学习 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%A9%BA%E9%97%B4%E6%9D%83%E9%87%8D%E7%9F%A9%E9%98%B5%E7%AE%80%E4%BB%8B"><span class="nav-text">1. 空间权重矩阵简介</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E9%82%BB%E6%8E%A5%E7%9F%A9%E9%98%B5"><span class="nav-text">1.1 邻接矩阵</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-1-1-%E5%9C%B0%E7%90%86%E9%82%BB%E6%8E%A5%E7%9F%A9%E9%98%B5"><span class="nav-text">1.1.1 地理邻接矩阵</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1-1-2-%E5%B9%BF%E4%B9%89%E2%80%9D%E7%9B%B8%E9%82%BB%E2%80%9D%E7%9F%A9%E9%98%B5"><span class="nav-text">1.1.2 广义”相邻”矩阵</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E8%B7%9D%E7%A6%BB%E7%9F%A9%E9%98%B5"><span class="nav-text">1.2 距离矩阵</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-2-1-%E5%9C%B0%E7%90%86%E8%B7%9D%E7%A6%BB%E7%9F%A9%E9%98%B5"><span class="nav-text">1.2.1 地理距离矩阵</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1-2-2-%E7%BB%8F%E6%B5%8E%E8%B7%9D%E7%A6%BB%E7%9F%A9%E9%98%B5"><span class="nav-text">1.2.2 经济距离矩阵</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-%E5%B5%8C%E5%A5%97%E7%9F%A9%E9%98%B5"><span class="nav-text">1.3 嵌套矩阵</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-3-1-%E5%9C%B0%E7%90%86%E7%BB%8F%E6%B5%8E%E5%B5%8C%E5%A5%97%E7%9F%A9%E9%98%B5%EF%BC%88%E7%9B%B8%E5%8A%A0%EF%BC%89"><span class="nav-text">1.3.1 地理经济嵌套矩阵（相加）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1-3-2-%E5%9C%B0%E7%90%86%E7%BB%8F%E6%B5%8E%E5%B5%8C%E5%A5%97%E7%9F%A9%E9%98%B5%EF%BC%88%E7%9B%B8%E4%B9%98%EF%BC%89"><span class="nav-text">1.3.2 地理经济嵌套矩阵（相乘）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1-3-3-%E5%9F%BA%E4%BA%8E%E5%BC%95%E5%8A%9B%E6%A8%A1%E5%9E%8B%E7%9A%84%E7%9F%A9%E9%98%B5"><span class="nav-text">1.3.3 基于引力模型的矩阵</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C"><span class="nav-text">2. 准备工作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E7%A4%BA%E4%BE%8B%E6%95%B0%E6%8D%AE"><span class="nav-text">2.1 示例数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4%E5%AE%89%E8%A3%85"><span class="nav-text">2.2 相关命令安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-mata-%E8%AF%AD%E8%A8%80%E7%9A%84%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95"><span class="nav-text">2.3 mata 语言的基础用法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-1-%E7%9F%A9%E9%98%B5%E5%B8%B8%E8%A7%84%E8%BF%90%E7%AE%97"><span class="nav-text">2.3.1 矩阵常规运算</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-2-%E7%9F%A9%E9%98%B5%E5%85%83%E7%B4%A0%E5%AF%B9%E5%85%83%E7%B4%A0%E8%BF%90%E7%AE%97"><span class="nav-text">2.3.2 矩阵元素对元素运算</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-3-%E5%BE%AA%E7%8E%AF"><span class="nav-text">2.3.3 循环</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-4-%E7%9F%A9%E9%98%B5%E5%AF%BC%E5%85%A5%E4%B8%8E%E5%AF%BC%E5%87%BA"><span class="nav-text">2.3.4 矩阵导入与导出</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E7%9F%A2%E9%87%8F%E5%9B%BE%E5%B1%82%E8%8E%B7%E5%8F%96%E3%80%81%E7%BC%96%E8%BE%91%E4%B8%8E%E5%AF%BC%E5%85%A5"><span class="nav-text">2.4 矢量图层获取、编辑与导入</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-1-%E7%9F%A2%E9%87%8F%E5%9B%BE%E5%B1%82%E8%8E%B7%E5%8F%96"><span class="nav-text">2.4.1 矢量图层获取</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-2-%E7%9F%A2%E9%87%8F%E5%9B%BE%E5%B1%82%E7%BC%96%E8%BE%91"><span class="nav-text">2.4.2 矢量图层编辑</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-3-%E7%9F%A2%E9%87%8F%E5%9B%BE%E5%B1%82%E5%AF%BC%E5%85%A5-Stata"><span class="nav-text">2.4.3 矢量图层导入 Stata</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-%E4%B8%80%E9%A2%97%E5%A5%BD%E5%A5%87%E5%BF%83"><span class="nav-text">2.5 一颗好奇心</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E7%A9%BA%E9%97%B4%E6%9D%83%E9%87%8D%E7%9F%A9%E9%98%B5%E7%9A%84%E6%9E%84%E5%BB%BA"><span class="nav-text">3. 空间权重矩阵的构建</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E5%9C%B0%E7%90%86%E9%82%BB%E6%8E%A5%E7%9F%A9%E9%98%B5"><span class="nav-text">3.1 地理邻接矩阵</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-1%E4%BD%BF%E7%94%A8-spmat-%E7%94%9F%E6%88%90%E5%9C%B0%E7%90%86%E9%82%BB%E6%8E%A5%E7%9F%A9%E9%98%B5"><span class="nav-text">3.1.1使用 spmat 生成地理邻接矩阵</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-2-%E5%85%B6%E4%BB%96%E7%94%9F%E6%88%90%E5%9C%B0%E7%90%86%E9%82%BB%E6%8E%A5%E7%9F%A9%E9%98%B5%E7%9A%84%E5%91%BD%E4%BB%A4"><span class="nav-text">3.1.2 其他生成地理邻接矩阵的命令</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E5%B9%BF%E4%B9%89%E2%80%9D%E7%9B%B8%E9%82%BB%E2%80%9D%E7%9F%A9%E9%98%B5"><span class="nav-text">3.2 广义”相邻”矩阵</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E5%9C%B0%E7%90%86%E8%B7%9D%E7%A6%BB%E7%9F%A9%E9%98%B5"><span class="nav-text">3.3 地理距离矩阵</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-1-spwmatrix-%E7%94%9F%E6%88%90%E5%9C%B0%E7%90%86%E8%B7%9D%E7%A6%BB%E7%9F%A9%E9%98%B5"><span class="nav-text">3.3.1 spwmatrix 生成地理距离矩阵</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-2-%E5%85%B6%E4%BB%96%E7%94%9F%E6%88%90%E5%9C%B0%E7%90%86%E8%B7%9D%E7%A6%BB%E7%9F%A9%E9%98%B5%E7%9A%84%E5%91%BD%E4%BB%A4"><span class="nav-text">3.3.2 其他生成地理距离矩阵的命令</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-%E7%BB%8F%E6%B5%8E%E8%B7%9D%E7%A6%BB%E7%9F%A9%E9%98%B5"><span class="nav-text">3.4 经济距离矩阵</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-5-%E5%9C%B0%E7%90%86%E7%BB%8F%E6%B5%8E%E5%B5%8C%E5%A5%97%E7%9F%A9%E9%98%B5%EF%BC%88%E7%9B%B8%E5%8A%A0%EF%BC%89"><span class="nav-text">3.5 地理经济嵌套矩阵（相加）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-6-%E5%9C%B0%E7%90%86%E7%BB%8F%E6%B5%8E%E5%B5%8C%E5%A5%97%E7%9F%A9%E9%98%B5%EF%BC%88%E7%9B%B8%E4%B9%98%EF%BC%89"><span class="nav-text">3.6 地理经济嵌套矩阵（相乘）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-7-%E4%BC%A0%E7%BB%9F%E5%BC%95%E5%8A%9B%E6%A8%A1%E5%9E%8B%E7%9F%A9%E9%98%B5"><span class="nav-text">3.7 传统引力模型矩阵</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-8-%E5%A4%A9%E9%A9%AC%E8%A1%8C%E7%A9%BA%E7%9A%84%E7%9F%A9%E9%98%B5"><span class="nav-text">3.8 天马行空的矩阵</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E7%BB%93%E8%AF%AD"><span class="nav-text">4. 结语</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">zhang jiaxing</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/star8kr/archives/">
        
          <span class="site-state-item-count">5</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/star8kr/categories/">
          
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/star8kr/tags/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">zhang jiaxing</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">27k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">1:07</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/star8kr/lib/anime.min.js"></script>
  <script src="/star8kr/lib/velocity/velocity.min.js"></script>
  <script src="/star8kr/lib/velocity/velocity.ui.min.js"></script>

<script src="/star8kr/js/utils.js"></script>

<script src="/star8kr/js/motion.js"></script>


<script src="/star8kr/js/schemes/pisces.js"></script>


<script src="/star8kr/js/next-boot.js"></script>




  




  
<script src="/star8kr/js/local-search.js"></script>













  

  

</body>
</html>
